package cn.zf233.xcloud.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zf233 on 2021/3/2
 * Redisson 配置类
 */
@Configuration
@ConditionalOnProperty(prefix = "xcloud", name = "cluster", havingValue = "true", matchIfMissing = true)
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.password}")
    private String password;

    @Bean(destroyMethod = "shutdown")
    public RedissonClient redissonClient() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + host + ":6379").setPassword(password);
        return Redisson.create(config);
    }
}
